﻿using Fortune.Context;
using FreeSql.Internal.Model;

namespace Fortune.DAO
{
    /// <summary>
    /// 抽象DAO层，提供了一些基础的对象获取方法
    /// </summary>
    public abstract class AbstractRepository
    {
        /// <summary>
        /// 拿到数据库连接
        /// </summary>
        /// <returns></returns>
        protected static IFreeSql getClient()
        {
            return FortuneContext.freeSql;
        }

        protected static DynamicFilterInfo like(string filed, object value)
        {
            return baseOperator(filed, DynamicFilterOperator.Contains, value);
        }

        protected static DynamicFilterInfo equal(string filed, object value)
        {
            return baseOperator(filed, DynamicFilterOperator.Equal, value);
        }

        private static DynamicFilterInfo baseOperator(string filed, DynamicFilterOperator dyOperator, object value)
        {
            return new DynamicFilterInfo
            {
                Field = filed,
                Operator = dyOperator,
                Value = value
            };
        }
    }
}